﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NL.ADA.ConfigService.DAL.EntityClasses;
using NL.ADA.ConfigService.DAL.DatabaseSpecific;
using NL.ADA.ConfigService.DAL.FactoryClasses;
using NL.ADA.ConfigService.DAL.HelperClasses;
using NL.ADA.ConfigService.DAL.RelationClasses;
using NL.ADA.ConfigService.DAL;
using SD.LLBLGen.Pro.ORMSupportClasses;


namespace NL.ADA.ConfigClient
{
    public class ApplicationManager:ManagerBase<ApplicationEntity>
    {
        public virtual int GetApplicationIdByCode(string code)
        {
            ApplicationEntity result = new ApplicationEntity();
            result.AppCode = code;
            try
            {
                using (DataAccessAdapter adapter = new DataAccessAdapter())
                {
                    IPredicateExpression expr = new PredicateExpression(ApplicationFields.AppCode == code);
                    adapter.FetchEntityUsingUniqueConstraint(result,expr);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result.Id;

        }
        public virtual DateTime GetModified(int appId, int modeId)
        {
            ApplicationModeModifiedEntity entity = new ApplicationModeModifiedEntity(appId,modeId);
            DateTime result;
            try
            {
                using(DataAccessAdapter adapter = new DataAccessAdapter())
                {
                    adapter.FetchEntity(entity);
                    result = entity.Modified;
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return result;
        }

    }
}
